package com.example.demo.config;

import com.example.demo.interceptor.Experyinterceptor;
import com.example.demo.interceptor.Userinterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@RequiredArgsConstructor
public class WebConfig implements WebMvcConfigurer {
    private final Userinterceptor userinterceptor;
    private final Experyinterceptor experyinterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
       registry.addInterceptor(userinterceptor).addPathPatterns("/user/**/*").excludePathPatterns("/user/user/login","/user/user/register","/user/user/uploadImg","/user/user/avatar");
       registry.addInterceptor(experyinterceptor).addPathPatterns("/expert/**/*").excludePathPatterns("/expert/login");
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .allowedHeaders("*")
                .allowCredentials(true)
                .maxAge(3600);
    }


} 